//
//  LKMyVideoViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/10.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKMyVideoViewController.h"
#import "LKElearnCollectionViewCell.h"
#import "LKElearningAvPlayerViewController.h"
#import "LLKCollectionManage.h"
@interface LKMyVideoViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,strong)UICollectionViewFlowLayout *flowLayout;
@property(nonatomic,strong)NSMutableArray *daAry;

@end

@implementation LKMyVideoViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setcollectionView];
    [self getMyCollctionVideo];
    
    // Do any additional setup after loading the view.
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"看过的视频";
}
/**
 设置collectionview
 */
-(void)setcollectionView{
    
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.itemSize = CGSizeMake((WIDTH - 45)/2, 175);
    self.flowLayout.minimumLineSpacing = 12;
    self.flowLayout.minimumInteritemSpacing = 9;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT + 12, WIDTH, HEIGHT - (NAVIGATION_BAR_HEIGHT + 12)) collectionViewLayout:self.flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"LKElearnCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"LKElearnCollectionViewCell"];
    [self.collectionView reloadData];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.daAry.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    LKElearnCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LKElearnCollectionViewCell" forIndexPath:indexPath];
    cell.model = self.daAry[indexPath.row];
    
    return cell;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(20, 16, 0, 16);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    LKElearningAvPlayerViewController *vc = [[LKElearningAvPlayerViewController alloc] init];
    vc.videoModel = self.daAry[indexPath.row];
    [self presentViewController:vc animated:YES completion:nil];
//    [self.navigationController pushViewController:vc animated:YES];
}

/**
 获取我收藏的视频
 */
-(void)getMyCollctionVideo{
    [self.daAry addObjectsFromArray:[[LLKCollectionManage shareManager] selectAll]];
//    for (LKVideoModel *videoModel in [[LLKCollectionManage shareManager] selectAll]) {
//
//        NSLog(@"%@",videoModel.collectionCount);
//    }
    [self.collectionView reloadData];
    [self.collectionView layoutIfNeeded];
//    NSLog(@"收藏的观看过的视频%@",watedArra);
}
-(NSMutableArray *)daAry{
    if (!_daAry) {
        _daAry = [[NSMutableArray alloc] init];
    }
    return _daAry;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
